<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AddColActivityGroupTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (!Schema::hasTable('activity_group')) {
            //拼团活动表
            Schema::create('activity_group', function(Blueprint $table) {
                $table->increments('id')->comment('自增id');
                $table->integer('goods_id')->default(0)->comment('商品id');
                $table->integer('max_group_num')->default(0)->comment('最大拼团人数');
                $table->timestamp('start_time')->nullable()->comment('活动开始时间');
                $table->timestamp('end_time')->nullable()->comment('活动结束时间');
                $table->integer('group_effective_time')->default(0)->comment('拼团有效时间（小时）');
                $table->integer('sort')->default(0)->comment('排序');
                $table->integer('status')->default(0)->comment('状态：0：下架 1：上架');
                $table->softDeletes();
                $table->timestamps();
            });
        }


        if (!Schema::hasTable('activity_group_add')) {
            //参与拼团活动表
            Schema::create('activity_group_add', function(Blueprint $table) {
                $table->increments('id')->comment('自增id');
                $table->integer('user_id')->default(0)->comment('用户id');
                $table->integer('group_id')->default(0)->comment('拼团id');
                $table->string('order_num')->nullable()->comment('订单编号');
                $table->integer('ag_id')->default(0)->comment('活动id');
                $table->integer('group_num')->default(0)->comment('实际拼团人数');
                $table->timestamp('start_time')->nullable()->comment('活动开始时间');
                $table->timestamp('end_time')->nullable()->comment('活动结束时间');
                $table->integer('status')->default(0)->comment('状态 0：进行中 1：拼团成功 2：拼团失败 3：退出拼团');
                $table->softDeletes();
                $table->timestamps();
            });
        }


        if (!Schema::hasTable('activity_group_refund')) {
            //拼团退款表
            Schema::create('activity_group_refund', function(Blueprint $table) {
                $table->increments('id')->comment('自增id');
                $table->integer('user_id')->default(0)->comment('用户id');
                $table->string('order_num')->nullable()->comment('订单编号');
                $table->string('reason')->nullable()->comment('退款原因');
                $table->timestamp('cancel_group')->nullable()->comment('取消拼团的时间');
                $table->timestamp('refund_time')->nullable()->comment('退款时间');
                $table->string('failure_reason')->nullable()->comment('失败原因');
                $table->integer('status')->default(0)->comment('状态 0：退款中 1：已退款 2：退款失败');
                $table->softDeletes();
                $table->timestamps();
            });
        }


        if (!Schema::hasTable('activity_group_price')) {
            //拼团活动拼团价设置表
            Schema::create('activity_group_price', function(Blueprint $table) {
                $table->increments('id')->comment('自增id');
                $table->integer('activity_group_id')->default(0)->comment('拼团活动id');
                $table->integer('goods_id')->default(0)->comment('商品id');
                $table->integer('goods_spu_id')->default(0)->comment('商品属性id');
                $table->decimal('many_price')->default(0)->comment('团购价');
                $table->softDeletes();
                $table->timestamps();
            });
        }

    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        //
    }
}
